Yahoo finance api is offline, to try and keep up with tutorial use https://eodhistoricaldata.com, it only works with AAPL.US for free
def graph_data(): stock_price_url = 'https://eodhistoricaldata.com/api/table.csv?s=AAPL.US&api_token=OeAFFmMliFG5orCUuwAKQ8l4WWFQ67YX' source_code = urllib.request.urlopen(stock_price_url).read().decode() stock_data =[] split_source = source_code.split('n') for line in split_source: split_line = line.split(',') if split_line[0] != 'Date': #ignore first line if (len(split_line)) == 7: #last line lenght is only 1 stock_data.append(line) date, openp, highp, lowp, closep, aclosep, volume = np.loadtxt(stock_data, delimiter=",", unpack=True, converters={0: bytespdate2num('%Y-%m-%d')} ) #different column order and date format
You must be logged in to post. Please login or register an account.
Hi VictorGXL. I came across the same problem today. Thanks for your answer. I haven't got it to work as it keeps telling me [date, openp, highp, lowp, closep, aclosep, volume = np.loadtxt (stock_data, NameError: name 'stock_data' is not defined]. Any ideas?
-whitingke 7 years ago
You must be logged in to post. Please login or register an account.
Your NameError comes from the fact that we haven't written that function yet, it comes in the next tutorial from the one you're working on!
-Harrison 7 years ago
You must be logged in to post. Please login or register an account.
Awesome Victor, thanks so much for sharing this! I think I'll host a local version too
-Harrison 7 years ago
You must be logged in to post. Please login or register an account.